import {
    toast,
    //formDownload
} from 'nc-lightapp-front';

import formDownload from 'src/hrpub/common/utils/download/download';
import language from '../../language';

import {unZipAndDecryptForForm} from 'src/hrpub/common/utils/unZipAndDecrypt';

export default function () {

    let {
        selectedRows,
        humanResourceOrganizationValue: {
            refpk
        }
    } = this.state;

    if (selectedRows.length <= 0) {
        toast({
            color: "warning",
            content: language['hi6007-000060']/* 国际化处理： 请勾选要处理的数据*/
        });
    } else {

        let jobs = selectedRows.map((item) => {
            return item.data.values.pk_psnjob.value
        });

        let postData = {
            pk_org: refpk,
            param_str: jobs.join(',')
        };

        /*formDownload({
            url: '/nccloud/hrhi/psndoc/PsndocExportPhotoAction.do',
            params: postData,
            enctype: 2
        })*/
        formDownload({
            url: '/nccloud/hrhi/psndoc/PsndocExportPhotoAction.do',
            body: postData,
            enctype: 2,
            onResult: (resBody) => {
                let innerText = resBody.innerText;
                let res = {};
                try {
                    res = JSON.parse(innerText);
                    if (typeof res === 'string') {
                        throw new Error();
                    }
                } catch (e) {
                    res = unZipAndDecryptForForm(innerText);
                }
                if (res.success) {
                    toast({
                        color: 'success',
                        content: language['hi6007-000183'] // 上传成功
                    });
                } else {
                    toast({
                        color: 'danger',
                        content: res.error.message
                    });
                }
            }
        });
    }

}
